/***
 * leetcode 203题
 */
public class LeetCode_203 {
    public ListNode removeElements(ListNode head, int val) {
        //第一个节点就是需要移除的节点
        while(head!= null && head.val == val){
            ListNode retNode = head;
            head = head.next;
            head.next = null;
        }

        if(null == head){
            return head;
        }

        ListNode preNode = head;
        while(preNode.next != null ){
            if(preNode.next.val == val){
                ListNode retNode = preNode.next;
                retNode.next = retNode.next;
                retNode.next = null;
            }else{
                preNode = preNode.next;
            }
        }
        return head;
    }
}
